#ifndef GAMESTATE_H
#define GAMESTATE_H

#include <QObject>
#include <QQmlEngine>

class GameState : public QObject
{
    Q_OBJECT
    Q_PROPERTY(int round READ round WRITE setRound NOTIFY roundChanged)
    Q_PROPERTY(QString turn READ turn WRITE setTurn NOTIFY turnChanged)
    Q_PROPERTY(QString stats READ stats NOTIFY statsChanged)
    Q_PROPERTY(bool win READ win NOTIFY winChanged)
    Q_PROPERTY(QList<QString> units READ units NOTIFY unitsChanged)
    QML_ELEMENT
public:
    explicit GameState(QObject *parent = nullptr);

    int round() {return _round;};
    void setRound(int round) {_round = round; emit roundChanged();}

    QString turn() {return _turn;}
    void setTurn(QString turn) {_turn = turn;emit turnChanged();}

    QString stats();

    bool win() {return _win;}

    QList<QString> units() {return board;}

    Q_INVOKABLE void dump_board();
    Q_INVOKABLE void place(int index);
    Q_INVOKABLE void replay();
signals:
    void roundChanged();
    void turnChanged();
    void statsChanged();
    void winChanged();
    void unitsChanged();

private:
    int _round;
    QString _turn;
    QMap<QString, int> _stats;
    bool _win = false;

    QList<QString> board;

    void reset_board();
    void check_board();

    // static void append_unit(QQmlListProperty<QString> *list, QString *unit);
};

#endif // GAMESTATE_H
